<template>
  <div>
    <swiper auto
            style="width:100%;margin-top:0;" height="200px"
            dots-class="custom-bottom"
            dots-position="center">

      <swiper-item class="swiper-demo-img" >
        <img src="../assets/swiper/veer-137107321.jpg">
      </swiper-item>

      <swiper-item class="swiper-demo-img">
        <img src="../assets/swiper/veer-144022479.jpg">
      </swiper-item>

      <swiper-item class="swiper-demo-img">
        <img src="../assets/swiper/veer-148936999.jpg">
      </swiper-item>


    </swiper>

    <grid   :cols="cols" >
      <span v-for="item in  gridItems">
        <grid-item :link="item.link" :label="item.label">
          <img slot="icon" :src="item.img">
        </grid-item>
      </span>
    </grid>
  </div>

</template>

<script>

  import {Swiper,SwiperItem } from 'vux'
  import {getUrlKey,getToken} from '@/utils'
  import {login} from '@/api/login'

  export default {
    name:"App",
    components: {
      Swiper,
      SwiperItem


    },
    created(){
      alert(location.href.split('#')[0])
      if(!getToken()){
        var code =getUrlKey("code");

        if(code){
          this.loginHandle(code);
        }
      }

      if(!this.$store.getters.token){
        this.$store.dispatch('setUserInfo');
      }


    },
    data () {
      return {
        menus: {
          menu1: 'Take Photo',
          menu2: 'Choose from photos'
        },
        showMenus: false,
        isShowNav:true,
        drawerVisibility: false,
        cols: 3,
        gridItems:[{
          link:'/',
          label:'点击1',
          img:'../static/menu_587px.png'
        },{
          link:'/',
          label:'点击2',
          img:'../static/grid_icon.png'
        },{
          link:'/',
          label:'点击3',
          img:'../static/grid_icon.png'
        },{
          link:'/',
          label:'点击1',
          img:'../static/grid_icon.png'
        },{
          link:'/',
          label:'点击2',
          img:'../static/grid_icon.png'
        },{
          link:'/',
          label:'点击3',
          img:'../static/grid_icon.png'
        },{
          link:'/',
          label:'点击1',
          img:'../static/grid_icon.png'
        },{
          link:'/',
          label:'点击2',
          img:'../static/grid_icon.png'
        },{
          link:'/',
          label:'点击3',
          img:'../static/grid_icon.png'
        }]
      }
    },
    methods:{
        loginHandle(code){
            login(code).then(result=>{
              let {data,code} = result.data;
              if(code === 0){
                  let {user,token} = data;
                  localStorage.setItem("user",JSON.stringify(user));
                  localStorage.setItem("token",token);
                  this.$store.dispatch('setUserInfo');
              }

            }).catch(error=>{

            });
        }


    }
  }
</script>


<style lang="less">




</style>
